<template>
    <div>
        {{ info }}
        <table>
            <thead>
                <tr>
                    <td>编号</td>
                    <td><input type="text" v-model="info.number" ></td>
                </tr>
                <tr>
                    <td>姓名</td>
                    <td><input type="text" v-model="info.wName" ></td>
                </tr>
                <tr>
                    <td>性别</td>
                    <td>
                        <input type="radio" v-model="info.sex" :value="1" >男
                        <input type="radio" v-model="info.sex" :value="0" >女
                    </td>
                </tr>
                <tr>
                    <td>手机号码</td>
                    <td><input type="text" v-model="info.phone" ></td>
                </tr>
                <tr>
                    <td>会员级别</td>
                    <td><select v-model="info.hid" >
                        <option value="">请选择</option>
                        <option :value="o.hId" v-for="o in fana" >{{ o.hName }}</option>
                    </select></td>
                </tr>
                <tr>
                    <td>加入日期</td>
                    <td><input type="date" v-model="info.date"  ></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="修改" @click="Add" ></td>
                </tr>
            </thead>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';

const route=useRoute();
const router=useRouter();

onMounted(()=>{
    List();
    FandUp();
})

let info:any=ref({
    "wId": route.query.id,
  "number": "",
  "wName": "",
  "sex": "",
  "phone": "",
  "hid": "0",
  "date": "",
  "state": 0,
  "isDell": 0
});

let fana:any=ref([]);


const FandUp=()=>{
    axios({
        url:'https://localhost:7033/api/User/Fandw',
        method:'post',
        params:{
            id:route.query.id
        }
    })
    .then((res)=>{
        console.log(res);
        Object.assign(info.value,res.data );
        info.value.date=moment(res.data.date ).format("yyyy-MM-DD")
    } )
}



const Add=()=>{
    axios({
        url:'https://localhost:7033/api/User/UpdateDto',
        method:'post',
        data:info.value
    })
    .then((res)=>{
        console.log(res);
        if(res.data==-1)
    {
        alert("用户名称相同");
        return;
    }
        if(res.data>0 )
    {
        alert("添加成功");
        return;
    }
    else
    {
        alert("失败");
    }
    })
    

}

const List=()=>{
    axios({
        url:'https://localhost:7033/api/User/ListW',
        method:'get'
    })
    .then((res)=>{
        console.log(res);
        fana.value=res.data
    })
}


</script>

<style scoped>

</style>